package com.test.demo.receive;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;

/**
 * 创建一个消息接受者,接收到消息，做出响应
 */
@Component
public class Receive {

    private static Logger logger=LoggerFactory.getLogger(Receive.class);
    private CountDownLatch latch=new CountDownLatch(1);

    public void receiveMessage(String message){
        logger.info("接收到的信息Receive：<"+message+">");
        latch.countDown();      //任务执行完成，将CountDownLatch的初始值减1
    }

    public CountDownLatch getLatch(){
        return latch;
    }
}
